﻿Imports System
Imports System.Collections.Generic
Imports System.Runtime.InteropServices
Imports System.Web.UI
Imports System.Web.UI.WebControls.WebParts
Imports Microsoft.SharePoint
Imports System.Web.Mvc
Imports System.Reflection
Imports System.Xml.Serialization
Imports System.ComponentModel
Imports Microsoft.SharePoint.Utilities
Imports Microsoft.SharePoint.WebPartPages


Namespace clsReproductor

    <Guid("3C1D4068-56BF-4734-9D04-EA56A2E3FD01")> _
    Public Class Reproductor_v1
        Inherits Microsoft.SharePoint.WebPartPages.WebPart


        Private _error As Boolean = False
        Private _MostrarControles As Boolean = True
        Private _InicioAutomatico As Boolean
        Private _IniciaMute As Boolean
        Private _Archivo As String
        Private _Alto As Integer
        Private _Ancho As Integer
        Private _ControlesCompletos As Boolean
        Private _EstadoReproduccion As Boolean


        <System.ComponentModel.Category("Configuraciones Del Reproductor")> _
        <Personalizable(PersonalizationScope.Shared)> <WebBrowsable(True)> _
        <WebDisplayName("Mostrar Controles")> _
        <WebDescription("")> _
        Public Property MostrarControles() As Boolean
            Get
                Return _MostrarControles
            End Get
            Set(ByVal value As Boolean)
                _MostrarControles = value
            End Set
        End Property

        <System.ComponentModel.Category("Configuraciones Del Reproductor")> _
        <Personalizable(PersonalizationScope.Shared)> <WebBrowsable(True)> _
       <WebDisplayName("Inicio Automatico")> _
       <WebDescription("")> _
        Public Property InicioAutomatico() As Boolean
            Get
                Return _InicioAutomatico
            End Get
            Set(ByVal value As Boolean)
                _InicioAutomatico = value
            End Set
        End Property

        <System.ComponentModel.Category("Configuraciones Del Reproductor")> _
       <Personalizable(PersonalizationScope.Shared)> <WebBrowsable(True)> _
      <WebDisplayName("Inicio en Mute")> _
      <WebDescription("")> _
        Public Property IniciaMute() As Boolean
            Get
                Return _IniciaMute
            End Get
            Set(ByVal value As Boolean)
                _IniciaMute = value
            End Set
        End Property

        <System.ComponentModel.Category("Configuraciones Del Reproductor")> _
      <Personalizable(PersonalizationScope.Shared)> <WebBrowsable(True)> _
     <WebDisplayName("Archivo a Reproducir")> _
     <WebDescription("")> _
        Public Property Archivo() As String
            Get
                Return _Archivo
            End Get
            Set(ByVal value As String)
                _Archivo = value
            End Set
        End Property

        <System.ComponentModel.Category("Configuraciones Del Reproductor")> _
      <Personalizable(PersonalizationScope.Shared)> <WebBrowsable(True)> _
     <WebDisplayName("Alto (Video)")> _
     <WebDescription("")> _
        Public Property Alto() As Integer
            Get
                Dim resultado As Integer = Nothing
                If _Alto <= 5 Then
                    resultado = 200
                Else
                    resultado = _Alto
                End If
                Return resultado
            End Get
            Set(ByVal value As Integer)
                _Alto = value
            End Set
        End Property

        <System.ComponentModel.Category("Configuraciones Del Reproductor")> _
      <Personalizable(PersonalizationScope.Shared)> <WebBrowsable(True)> _
     <WebDisplayName("Ancho (Video)")> _
     <WebDescription("")> _
        Public Property Ancho() As Integer
            Get
                Dim resultado As Integer = Nothing
                If _Ancho <= 5 Then
                    resultado = 200
                Else
                    resultado = _Ancho
                End If
                Return resultado
            End Get
            Set(ByVal value As Integer)
                _Ancho = value
            End Set
        End Property

        <System.ComponentModel.Category("Configuraciones Del Reproductor")> _
              <Personalizable(PersonalizationScope.Shared)> <WebBrowsable(True)> _
             <WebDisplayName("Estado Reproducción")> _
             <WebDescription("")> _
        Public Property EstadoReproduccion() As Boolean
            Get
                Return _EstadoReproduccion
            End Get
            Set(ByVal value As Boolean)
                _EstadoReproduccion = value
            End Set
        End Property

        Public Sub New()
            Me.ExportMode = WebPartExportMode.All
        End Sub


        Protected Overloads Overrides Sub CreateChildControls()
            If Not _error Then
                Try
                    'Dim aux As New label
                    MyBase.CreateChildControls()
                    Me.Controls.Add(Page.LoadControl("~/_controltemplates/RepMed.ascx"))
                    'Me.Controls.Add(Page.LoadControl())
                    'Me.Controls.Add(New LiteralControl(Me.ChildControlsCreated))
                Catch ex As Exception
                    HandleException(ex)
                End Try
            End If
        End Sub



        Protected Overrides Sub RenderWebPart(ByVal output As HtmlTextWriter)
            'output.Write(SPEncode.HtmlEncode(BarraMenu))
            output.Write("<object id='playera' height='" & Alto() & "' width='" & Ancho() & "' classid='clsid:22d6f312-b0f6-11d0-94ab-0080c74c7e95'>")
            output.Write("<param name='autostart' value='" & InicioAutomatico() & "' />")
            output.Write("<param name='showcontrols' value='" & MostrarControles() & "' />")
            output.Write("<param name='mute' value='" & IniciaMute() & "' />")
            output.Write("<param name='filename' value='" & Archivo() & "' />")
            output.Write("<param name='enabled' value='-1' />")
            output.Write("<param name='showstatusbar' value='" & EstadoReproduccion() & "' />")
            output.Write("</object>")
            'output.Write("
            'output.Write("
            'output.Write("
        End Sub




        Protected Overloads Overrides Sub OnLoad(ByVal e As EventArgs)
            If Not _error Then
                Try
                    MyBase.OnLoad(e)


                    Me.EnsureChildControls()

                Catch ex As Exception
                    HandleException(ex)
                End Try
            End If
        End Sub

        Private Sub HandleException(ByVal ex As Exception)
            Me._error = True
            Me.Controls.Clear()
            Me.Controls.Add(New LiteralControl(ex.Message))
        End Sub

        'Public Function ReproductorString()
        '    Reproductor = "<object id='playera' height='230' width='230' classid='clsid:22d6f312-b0f6-11d0-94ab-0080c74c7e95'>" _
        '      & "<param name='autostart' value='true' />" _
        '      & "<param name='balance' value='false' />" _
        '      & "<param name='displaysize' value='true' />" _
        '      & "<param name='filename' value='' />" _
        '      & "<param name='mute' value='false' />" _
        '      & "<param name='selectionstart' value='false' />" _
        '      & "<param name='selectionend' value='false' />" _
        '      & "<param name='showcontrols' value='" & BarraMenu() & "' />" _
        '      & "<param name='showaudiocontrols' value='" & BarraMenu() & "' />" _
        '      & "<param name='showdisplay' value='" & BarraMenu() & "' />" _
        '      & "<param name='showpositioncontrols' value='false' />" _
        '      & "<param name='volume' value='1' />" _
        '      & "<param name='audiostream' value='false' />" _
        '      & "<param name='autosize' value='false' />" _
        '      & "<param name='animationatstart' value='false' />" _
        '      & "<param name='allowscan' value='false' />" _
        '      & "<param name='allowchangedisplaysize' value='false' />" _
        '      & "<param name='autorewind' value='true' />" _
        '      & "<param name='baseurl' value='' />" _
        '      & "<param name='bufferingtime' value='5' />" _
        '      & "<param name='captioningid' value='' />" _
        '      & "<param name='clicktoplay' value='true' />" _
        '      & "<param name='cursortype' value='0' />" _
        '      & "<param name='currentposition' value='true' />" _
        '      & "<param name='currentmarker' value='true' />" _
        '      & "<param name='defaultframe' value='mainframe' />" _
        '      & "<param name='displaybackcolor' value='true' />" _
        '      & "<param name='displayforecolor' value='16777215' />" _
        '      & "<param name='displaymode' value='1' />" _
        '      & "<param name='enabled' value='-1' />" _
        '      & "<param name='enablecontextmenu' value='false' />" _
        '      & "<param name='enablepositioncontrols' value='false' />" _
        '      & "<param name='enablefullscreencontrols' value='false' />" _
        '      & "<param name='enabletracker' value='false' />" _
        '      & "<param name='invokeurls' value='false' />" _
        '      & "<param name='language' value='false' />" _
        '      & "<param name='playcount' value='1' />" _
        '      & "<param name='previewmode' value='false' />" _
        '      & "<param name='showstatusbar' value='true' />" _
        '      & "<param name='transparentatstart' value='false' />" _
        '      & "</object>"

        '    Return Reproductor
        'End Function

    End Class
End Namespace